package com.dgut.smart_house.util;

import com.dgut.smart_house.withHardware.AppBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Map;
import java.util.Properties;

public class MailUtil {


    public  void sendMail(Map map) {
        JavaMailSenderImpl javaMailSender=new JavaMailSenderImpl();
        javaMailSender.setUsername("1421050929@qq.com");
        javaMailSender.setHost("smtp.qq.com");
        javaMailSender.setPassword("wmcrldbvjbmzhbjd");
        javaMailSender.setDefaultEncoding("UTF-8");

        //简单邮件
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        //标题
        simpleMailMessage.setSubject("Warn!智能家居系统异常数据通知");
        //内容
        /**
         * map.put("userId",user.getUserId());
         * map.put("desc",device1.getDesc());
         * map.put("node",node.getNodeName());
         * map.put("email",user.getEmail());
         */
        String str = "！！异常通知\n" +
                "您" + map.get("userId") + "该家庭账号下位于 " + map.get("desc") + " 的 " + map.get("node") + " 设备" + "接收到了异常数据\n" +
                "请及时查看设备状况并处理异常！";
        simpleMailMessage.setText(str);
        //发送方
//        simpleMailMessage.setTo((String) map.get("email"));
        simpleMailMessage.setTo("yuec19981227@163.com");
        simpleMailMessage.setFrom("1421050929@qq.com");
        try {
            javaMailSender.send(simpleMailMessage);
            System.out.println("----邮件已发送！----");
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
